package com.visitorspecials.tankbattle.server;

import java.util.*;

public class Tank extends MovingActor
{
	final static float TANK_SIZE = 0.3f;

	protected float turretHeading;

	protected int _health;

	public Tank(Vector2 loc, ArrayList<Actor> list)
	{
		super("tank", loc, TANK_SIZE, Vector2.zero, list);

		_health = 5;
	}

	public void wasShotBy(Bullet b)
	{
		if (this.isColidingWith(b))
		{
			_health -= b.getDamage();
			b.destroy();
		}
	}

	public void fireShot(Vector2 loc) // To be implemented by Will/Dylan
	{
		Vector2 toConvert = Vector2.subtract(loc, this._location);
		/*Vector2 toConvert = new Vector2(loc.x - this._location.x, loc.y
				- this._location.y);*/
		turretHeading = -Vector2.AngleFromVector(toConvert) + 180;

		toConvert.Normalize();
		toConvert.x = toConvert.x * 5;
		toConvert.y = toConvert.y * 5;

		Bullet b = new Bullet("Bullet", this._location, 2f, toConvert, 5,
				_list);
	}

	@Override
	public String toString()
	{
		return super.toString()
				+ String.format("::turret:%f:%f:%f:%f", this._location.x,
						this._location.y, this.turretHeading, 0.2f);
	}
}
